/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Gsb.Andro;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import java.util.List;
import modele.Med;

/**
 *
 * @author plasalmonie
 */
public class MedAdapter extends BaseAdapter {

    private List<Med> lesMeds;
    private Context c;

    MedAdapter(List data, Context c) {
        lesMeds = data;
        this.c = c;
    }

    public int getCount() {
        return lesMeds.size();
    }

    public Object getItem(int i) {
        return lesMeds.get(i);
    }

    public long getItemId(int i) {
        return i;
    }

    public View getView(int i, View v, ViewGroup vg) {
        // Création de la vue en analysant le xml lignechev
        LayoutInflater vi = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.unmed, null);
        TextView nomView = (TextView) v.findViewById(R.id.nom);
        TextView specialiteView = (TextView) v.findViewById(R.id.specialite);
        TextView departementView = (TextView) v.findViewById(R.id.departement);
        Med leMed = lesMeds.get(i);
        nomView.setText(leMed.getNom().toUpperCase() + ' ' + leMed.getPrenom());
        String[] splitAddress = leMed.getAdresse().split(" ");
        if (splitAddress.length > 1) {
            departementView.setText(splitAddress[splitAddress.length - 2]);
        }
        if (leMed.getSpe().equals("")) {
            specialiteView.setText("Généraliste");
        } else {
            specialiteView.setText(leMed.getSpe());
        }
        return v;
    }
}
